This page last changed on Sep 24, 2007 by jdeolive.

LESSON 3: Google Earth

Objective:
In this tutorial you will learn how to use some the features of GeoServer Google Earth support.

Section 1: Viewing Data in Google Earth
Section 2: Filtering Data with CQL
Section 3: Customizing Placemark Descriptions with Templates
Section 4: Time with Templates
Section 5: Extra Credit

0) Set Google Earth to OpenGL Mode

Before you begin, you must configure Google Earth to work in OpenGL mode. In Google Earth:

  1. Navigate to Tools -> Options from the main menu
  2. On the 3DView tab, set graphics mode to OpenGL
  3. Click Apply and restart Google Earth.

1) Viewing Data in Google Earth

The easiest way to view a layer in Google Earth is via the GeoServer web interface.

  1. In your web browser and navigate to http://localhost:8080/geoserver/mapPreview.do
  2. Select the KML link located to the right of the topp:states link


  3. Ensure Google Earth is selected from the Open with drop down, and click OK

Google Earth will now open and render the KML produced by GeoServer. At this point you should see the following:

2) Filtering Data with CQL

GeoServer has a powerful capability to limit the data returned based on a query passed in by the user. In this section you will learn how to use the CQL_FILTER paramter of a kml request to limit the amount of data that is returned, and to doe some interesting queries. "CQL" stands for "Common Query Language", and is a useful syntax for specifying queries against a dataset. More information about CQL is available here.

  1. In Google Earth, delete the states layer that was added in the previous section.

Next you will create a kml request which specifies an cql filter.

  1. In your web browser, enter the following url into the address bar:
    http://localhost:8080/geoserver/wms/kml_reflect?layers=states&cql_filter=STATE_ABBR+=+'TX'
    

    The above query specifies that only the feature with STATE_ABBR (state abbreviation) equal to TX (Texas) should be returned. At this point
    you should see the single feature for Texas rendered in Google Earth.


  2. Repeat the previous step for the following queries
    • Those states which have a population of less than 2 million
      http://localhost:8080/geoserver/wms/kml_reflect?layers=states&cql_filter=PERSONS+<+2000000
      



    • Those states which have a greater male population than a female population
      http://localhost:8080/geoserver/wms/kml_reflect?layers=states&cql_filter=FEMALE+<+MALE
      

3) Custom Placemarks with Templates

An extremely powerful GeoServer feature is the ability to customize KML placemark (popup) descriptions. This is achieved with a template. A template is a simple text file which contains a combination of HTML markup, and attribute references. In this section you will learn how to use templates to create placemark descriptions custom to your dataset.

  1. In Google Earth, delete or turn off any layers added from the previous section
  2. Following steps from section 1, open the states layer in Google Earth.
  3. In Google Earth, click on the Placemark Icon for California

This is the default placemark description that GeoServer produces. Next you will create the template to customize it to this dataset.

  1. In a file explorer, navigate to the C:\Program Files\GeoServer 1.6-beta3\data_dir\featureTypes\states directory
  2. Open the file named description.ftl in a text editor ( right click and Select Edit with Notepad++ )
  3. Clear the contents of the file

In a template, the value of attributes from the dataset are available using a special "variable syntax". For instance, if we want to access the STATE_NAME attribute, we use the expression:

{${STATE_NAME.value}}
  1. Add an HTML img tag to the template which references an image for the flag of the state:
    <img src="http://www.netstate.com/states/symb/flags/images/${STATE_ABBR.value?lower_case}_fi.gif" height="100" width="175"/>
    <br>
    <br>
    

    Here using the value of the STATE_ABBR (state abbreviation) attribute, you have dynamically created to image of the flag. This also illustrates the use of functions. Functions can used to transform attribute values. In this case the function lower_case is being used to tranform the state abbreviation to lower case.

  2. Use the values of the STATE_NAME and PERSONS attributes to add a sentence which states the name of the state and its population:
    This is the state of ${STATE_NAME.value} which has a population of ${PERSONS.value}.
    <br>
    <br> 
    
  3. Use the STATE_NAME attribute to create a link to the Wikipedia page for the state.
    Check out more information on <a href="http://en.wikipedia.org/wiki/${STATE_NAME.value?replace(" ", "_")}">Wikipedia</a>.
    

    This again illustrates the use of a function in order to replace all spaces in the state name with an underscore.

  4. Save description.ftl

At this point, your description.ftl template should have the following content:

<img src="http://www.netstate.com/states/symb/flags/images/${STATE_ABBR.value?lower_case}_fi.gif" height="100" width="175"/>
<br>
<br>
This is the state of ${STATE_NAME.value} which has a population of ${PERSONS.value}.
<br>
<br>
Check out more information on <a href="http://en.wikipedia.org/wiki/${STATE_NAME.value?replace(" ", "_")}">Wikipedia</a>.
  1. In Google Earth refresh the view by panning around or changing the zoom
  2. Again click on the Placemark Icon for California

4) Time with Templates

Another interesting application of templates in GeoServer is with time. KML placemarks may have an optional "timestamp" attribute. When included in KML Google Earth will render the placemark only when it falls into the range of a specified time period. In this section you will learn how to use a template to specify a temporal attribute of a dataset.

First you will set up a dataset which contains temporal information. Using the steps from lesson one:

  1. Add the style inet_weu_style:
    1. In your web browser go to http://localhost:8080/geoserver/welcome.do and navigate the links Config->Styles->New
    2. Use the Browse... button to locate the file inet_weu.sld at C:\Program Files\GeoServer 1.6-beta3\data_dir\data/shapefiles\inet_weu.sld
    3. Click the Upload button
    4. Click Submit, Apply, and then Save
  2. Using the steps from lesson one add the shapefile inet_weu.shp located at file:data/shapefiles/inet_weu.shp (this is a GeoServer datastore relative path)
    1. Create the shapefile datastore inet_weu
    2. Set the style of the layer to the inet_weu_style added in step 1.
    3. Submit, Apply, and Save

Next you will add the layer to Google Earth using steps from previous sections.

  1. Add the inet_weu layer with the following kml request:
    http://localhost:8080/geoserver/wms/kml_reflect?layers=inet_weu
  2. In Google Earth, move the view to western Europe

Next you will create the template which is used to specify the temporal attribute of the dataset. The attribute in question is called RPT_YEAR and is the 4 digit year.

  1. In a file explorer, navigate to the C:\Program Files\GeoServer 1.6-beta3\data_dir\featureTypes\inet_weu_inet_weu directory
  2. Create a new file called time.ftl and open it in a text editor
    1. Right-click and select New-->Text Document
    2. Rename the file to time.ftl
    3. Confirm the change of filename extension
    4. Right click on time.ftl and select Edit with Notepad++
  3. Specify the time attribute RPT_YEAR in the template:
    ${RPT_YEAR.value?date("yyyy")}
    
  4. Save time.ftl
  5. In Google Earth ensure the inet_weu.kml layer is selected and refresh the view by panning around or changing the zoom. You should now see a time bar at the top of the screen:
  6. On the time bar located at the top of the screen change the time interval so it is just over 1 year
  7. Slide the time bar forward in time and notice how the polygon colors change

5) Extra Credit

Done Early? Here are some additional activities you can try out.

Super Overlays

GeoServer supports "Region Based KML", or "Super Overlays", more information here. Specifying a super overlay can be done by appending &superoverlay=true to a KML request. Try it out with some GeoServer layers and see what happens as you zoom in.

Scoring

KML "Scoring" is a feature which can be used to control how GeoServer returns KML. GeoServer can return KML in vector form or raster form. Returning large volumes of data in vector (placemark) form puts a heavy rendering load on Google Earth and can degrade performance quite drastically. In cases such as these it is useful to have GeoServer turn KML in raster (overlay) form.

Read through the information here and play with different values of the KMSCORE parameter and note the results.

Advanced Placemarks

Continue with skills learned in Section 3 and play around creating some of your own placemark descriptions. For some inspiration check out some of the examples here.


kmlLink.png (image/png)
kmlLink.png (image/png)
open.png (image/png)
ge.png (image/png)
tx.png (image/png)
delege.png (image/png)
cql2.png (image/png)
cql1.png (image/png)
template2.png (image/png)
template1.png (image/png)
uploadStyle.png (image/png)
setStyle.png (image/png)
addStyle.png (image/png)
newStyle.png (image/png)
addShapefile.png (image/png)
newShapefile.png (image/png)
time4.png (image/png)
time3.png (image/png)
time2.png (image/png)
time1.png (image/png)
Document generated by Confluence on Jan 16, 2008 23:27